import java.util.concurrent.Semaphore;

/**
 * @projectName: java-daily-questions
 * @package: PACKAGE_NAME
 * @className: VariableDemo
 * @author: ZM
 * @description: 变量的线程安全 - demo
 * @date: 2021/8/21 18:29
 * @version: 1.0
 */
public class VariableDemo {

    private volatile static int i = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread a = new Thread(() -> {
            for( int j = 0 ; j < 1000000 ; j++ ) i++;
        });
        a.start();
        Thread b = new Thread(() -> {
            for( int j = 0 ; j < 1000000 ; j++ ) i--;
        });
        b.start();
        a.join();
        b.join();
        System.out.println(i);
    }
}
